package com.example.demo.dao;

import com.example.demo.dao.DepartmentDao;
import com.example.demo.pojo.Department;
import com.example.demo.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;


import java.util.Collection;
import java.util.HashMap;
@Repository
public class EmployeeDao {
   private static HashMap<Integer,Employee> employees=null;
   @Autowired
   private DepartmentDao departmentDao;

    static{
       employees=new HashMap<Integer,Employee>();
       employees.put(101,new Employee(101,"C罗","215564646@qq.com", 1, new Department(101, "巴黎圣日耳曼")));
       employees.put(102,new Employee(102,"梅西","215564646@qq.com", 1, new Department(102, "巴萨罗那")));
       employees.put(103,new Employee(103,"格列兹曼","215564646@qq.com", 1, new Department(103, "拜仁慕尼黑")));
       employees.put(104,new Employee(104,"阿扎尔","215564646@qq.com", 1, new Department(104, "皇家马德里")));
       employees.put(105,new Employee(105,"内马尔","215564646@qq.com", 1, new Department(105, "巴黎圣日耳曼")));
       employees.put(106,new Employee(106,"贝克汉姆","215564646@qq.com", 1, new Department(107, "曼城")));
   }
   private Integer iid=107;

    //   增加一个球星
public void save(Employee employee){
    if(employee.getId()==null){
        employee.setId(iid++);
    }
    employee.setDepartment(departmentDao.query(employee.getDepartment().getId()));
    employees.put(employee.getId(),employee);
}
//得到全部球星
    public Collection<Employee> getEmployee(){
    return employees.values();
    }
//    通过Id查询球星
    public Employee Equery(int id){
    return employees.get(id);
    }
//    删除球星
    public void delete(int id){
     employees.remove(id);
    }
}
